package com.gxuwz.medical.web.servlet.menu;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.dao.MenuDao;
import com.gxuwz.medical.domain.menu.Menu;
import com.gxuwz.medical.web.servlet.BaseServlet;

import net.sf.json.JSONArray;

public class LoadMenuTreeServlet extends BaseServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("进入权限树查询");
		TreesList(request, response);

	}

	private void TreesList(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		MenuDao menuDao = new MenuDao();
		List<Menu> menu_tree_list = menuDao.getAllMenu();
		String treeNodesJson = JSONArray.fromObject(menu_tree_list).toString();// 将list列表转换成json格式 返回

		PrintWriter out = response.getWriter();
		// 利用Json插件将Array转换成Json格式
		out.print(treeNodesJson);
		System.out.println("menu_tree_list=" + menu_tree_list);
		// 释放资源
		out.close();

	}
}
